﻿namespace BlazorShop.Models
{
    public class Cart
    {
        public List<LineItem> Items { get; set; }
        public float TotalPrice { get; set; }

        public Cart() 
        {
            Items = new List<LineItem>();
            TotalPrice = 0;
        }

        public void AddProduct(Product product)
        {
            bool flag = false;
            foreach  (var item in Items) { 
                if (item.Product.ProductId == product.ProductId) {
                    item.Quantity++;
                    flag = true;
                }
            }
            if (!flag) { 
                LineItem item = new LineItem();
                item.Product = product;
                item.Quantity = 1;
                item.UnitPrice = product.Price;
                Items.Add(item);
            }
        }

        //internal void AddProduct(Task<Product?> product)
        //{
        //    throw new NotImplementedException();
        //}
    }
}
